11 const int MAXN
= 1000, MAXC
= 100;
16 edge(int I
, int G
, int W
) : i(I
), g(G
), w(W
) {}
17 bool operator < (const edge
&that
) const {
22 int p
[MAXN
], d
[MAXN
][MAXC
+1], n
;
26 int dijkstra(const int &start
, const int &end
, const int &c
){
27 for (int i
=0; i
<n
; ++i
)
28 for (int j
=0; j
<=c
; ++j
)
31 priority_queue
<edge
> q
;
32 q
.push(edge(start
, 0, 0));
39 //printf("popped <%d, %d, %d>\n", u.i, u.g, u.w);
43 if (d
[u
.i
][u
.g
] < u
.w
) continue;
45 //I can buy another gallon and stay where I am
46 if (u
.g
< c
&& u
.w
+ p
[u
.i
] < d
[u
.i
][u
.g
+1]){
47 d
[u
.i
][u
.g
+1] = u
.w
+ p
[u
.i
];
48 q
.push(edge(u
.i
, u
.g
+1, u
.w
+ p
[u
.i
]));
51 //Now try to reach each other node as long as I have enough gas
52 vector
<edge
> &v
= g
[u
.i
];
53 for (int j
=0; j
<v
.size(); ++j
){
54 int distance
= v
[j
].w
;
55 int neighbor
= v
[j
].i
;
57 int new_gas
= u
.g
- distance
;
58 if (u
.w
< d
[neighbor
][new_gas
]){
59 d
[neighbor
][new_gas
] = u
.w
;
60 q
.push(edge(neighbor
, new_gas
, u
.w
));
71 scanf("%d %d", &n
, &m
);
72 for (int i
=0; i
<n
; ++i
){
78 scanf("%d %d %d", &u
, &v
, &d
);
79 g
[u
].push_back(edge(v
, 0, d
));
80 g
[v
].push_back(edge(u
, 0, d
));
87 scanf("%d %d %d", &c
, &s
, &e
);
88 int t
= dijkstra(s
, e
, c
);
92 printf("impossible\n");